package com.thinkgem.jeesite.common.pojo.doc.xml;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.SAXException;

/** * * @author hongliang.dinghl * SAX文档解析 */
public class XmlSAX extends XmlDoc {

//	public void createXml(String fileName) {
//		System.out.println("<<" + fileName + ">>");
//	}

	//sax没有createXml的方法,主要针对只读属性的xml进行事件驱动式的顺序解析.
	public void parserXml(String fileName) {
		SAXParserFactory saxfac = SAXParserFactory.newInstance();
		try {
			SAXParser saxparser = saxfac.newSAXParser();
			InputStream is = new FileInputStream(fileName);
			saxparser.parse(is, new XmlSAXHandler());
		} catch (ParserConfigurationException e) {
			e.printStackTrace();
		} catch (SAXException e) {
			e.printStackTrace();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void parserExt(String fileName) {
		SAXParserFactory saxfac = SAXParserFactory.newInstance();
		try {
			SAXParser saxparser = saxfac.newSAXParser();
			InputStream is = new FileInputStream(fileName);
			XmlSAXHandler myhandler = new XmlSAXHandler();
			saxparser.parse(is, myhandler);
		} catch (ParserConfigurationException e) {
			e.printStackTrace();
		} catch (SAXException e) {
			e.printStackTrace();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		XmlSAX xml = new XmlSAX();
		String fName = "D:\\workspace\\KWOA\\resources\\dao\\ext\\project\\modules\\business\\de-business.xml";
		xml.setFileName(fName);
		//xml.init();
		//xml.createXml(xml.fileName);
		xml.parserXml(xml.fileName);
	}


}

